package com.astn.payment.paypal;

import android.content.Context;

import com.paypal.android.MEP.PayPal;

public class AstnPayPalPayment {
	private static final String appId = "APP-80W284485P519543T";
	private PayPal paypal;
	private static final int server = PayPal.ENV_SANDBOX;
	private Context context;
	public static final int INITIAL_SUCCESS = 1;
	public static final int INITIAL_FAIL = 0;
	private int initialStatus;

	public PayPal getPaypal() {
		return paypal;
	}

	public int getInitialStatus() {
		return initialStatus;
	}

	public AstnPayPalPayment(Context context) {
		this.context = context;
		paypal = PayPal.getInstance();
		if (paypal == null) {
			paypal = PayPal.initWithAppID(this.context, appId, server);

			// -- These are required settings.
			paypal.setLanguage("en_US"); // Sets the language for the library.
			// --

			// -- These are a few of the optional settings.
			// Sets the fees payer. If there are fees for the transaction, this
			// person will pay for them. Possible values are FEEPAYER_SENDER,
			// FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER, and
			// FEEPAYER_SECONDARYONLY.
			paypal.setFeesPayer(PayPal.FEEPAYER_SENDER);
			// Set to true if the transaction will require shipping.
			paypal.setShippingEnabled(true);
			// Dynamic Amount Calculation allows you to set tax and shipping
			// amounts based on the user's shipping address. Shipping must be
			// enabled for Dynamic Amount Calculation. This also requires you to
			// create a class that implements PaymentAdjuster and Serializable.
			paypal.setDynamicAmountCalculationEnabled(false);
			// --

		}
		if (PayPal.getInstance().isLibraryInitialized()) {
			initialStatus = INITIAL_SUCCESS;

		} else {
			initialStatus = INITIAL_FAIL;
		}
	}
}
